//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


//----------------------------------------------------------------------------------------
// patterns & practices - Smart Client Software Factory - Guidance Package
//
// This file was generated by the "Add WPF View" recipe.
//
// A presenter calls methods of a view to update the information that the view displays. 
// The view exposes its methods through an interface definition, and the presenter contains
// a reference to the view interface. This allows you to test the presenter with different 
// implementations of a view (for example, a mock view).
//
// For more information see:
// ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ms.practices.scsf.2007may/SCSF/html/02-09-010-ModelViewPresenter_MVP.htm
//
// Latest version of this Guidance Package: http://go.microsoft.com/fwlink/?LinkId=62182
//----------------------------------------------------------------------------------------

using System;
using System.Windows;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI.WPF;
using Microsoft.Practices.ObjectBuilder;

using LitwareHR.Infrastructure.Interface;
using System.Data;
using System.Windows.Controls;
using LitwareHR.Recruiting.Contract;
using System.Windows.Media.Animation;

namespace LitwareHR.PublicApp.WinUX
{
    /// <summary>
    /// Interaction logic for CandidatesView.xaml
    /// </summary>
    public partial class CandidatesView : System.Windows.Controls.UserControl, ICandidatesView, IDisposable
    {
        /// <summary>
        /// Initialize a new instance of <see cref="CandidatesView"/>.
        /// <summary>
        public CandidatesView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(OnLoad);
        }

        /// <summary>
        /// Called when WPF has loaded the control and is ready to display it.
        /// <summary>
        /// <param name="sender">Source of the event</param>
        /// <param name="e">Extra information about the event</param>
        void OnLoad(object sender, RoutedEventArgs e)
        {
            _presenter.OnViewReady();
        }

        void OnCandidatesListView_SelectionChanged(object sender, RoutedEventArgs e)
        {
            object selectedCandidate = ((ListView)e.Source).SelectedItem;

            _presenter.OnCandidateSelected(selectedCandidate);
        }

        #region ICandidatesView Members

        public void SetUpControls()
        {
            webBrowser.ScrollBarsEnabled = false;
            webBrowser.IsWebBrowserContextMenuEnabled = false;
            webBrowser.WebBrowserShortcutsEnabled = false;            
            webBrowser.Height = 225;            
        }

        public void LoadResources()
        {
            // Merge resoure directory
            base.Resources.MergedDictionaries.Add((ResourceDictionary)Application.LoadComponent(new Uri(@"Litware.HR;;;component/Views/Skins/BaseSkin.xaml", UriKind.Relative)));
        }

        public void ShowCandidates(DataTable candidates)
        {
            this.CandidatesListView.DataContext = candidates;
        }

        public void ShowResume(Resume resume, Uri videoResumeUri)
        {
           this.DataContext = resume;
           webBrowser.Navigate(videoResumeUri);
        }

        public void ShowWebBrowser()
        {
            this.ResumeStackPanel.Visibility = Visibility.Visible;
            this.OfflineStackPanel.Visibility = Visibility.Hidden;
            this.VideoUploadStateTextBlock.Visibility = Visibility.Hidden;
            this.VideoResumeTextBlock.Visibility = Visibility.Visible;
            this.WebBrowserStackPanel.Visibility = Visibility.Visible;
        }

        public void ShowOfflinePanel()
        {
            this.ResumeStackPanel.Visibility = Visibility.Hidden;
            this.OfflineStackPanel.Visibility = Visibility.Visible;
            this.VideoUploadStateTextBlock.Visibility = Visibility.Hidden;
            this.VideoResumeTextBlock.Visibility = Visibility.Hidden;
            this.WebBrowserStackPanel.Visibility = Visibility.Hidden;
        }

        public void ShowNoVideoAvailableMessage(string msg)
        {
            this.ResumeStackPanel.Visibility = Visibility.Visible;
            this.OfflineStackPanel.Visibility = Visibility.Hidden;
            this.VideoResumeTextBlock.Visibility = Visibility.Visible;
            this.VideoUploadStateTextBlock.Visibility = Visibility.Visible;
            this.VideoUploadStateTextBlock.Text = msg;
            this.WebBrowserStackPanel.Visibility = Visibility.Hidden;
        }

        public void HideWebBrowser()
        {
            this.ResumeStackPanel.Visibility = Visibility.Visible;
            this.OfflineStackPanel.Visibility = Visibility.Hidden;
            this.VideoResumeTextBlock.Visibility = Visibility.Hidden;
            this.VideoUploadStateTextBlock.Visibility = Visibility.Hidden;
            this.WebBrowserStackPanel.Visibility = Visibility.Hidden;
        }

        /// <summary>
        /// This method is used to Notify Schema Changes
        /// </summary>
        public void NotifySchemaChanges()
        {
            tbSchemaChanged.Visibility = Visibility.Visible;
            imgSchemaChanged.Visibility = Visibility.Visible;
            Storyboard StoryboardSchemaChanged = (Storyboard)FindResource("StoryboardSchemaChanged");
            StoryboardSchemaChanged.Begin(rootCanvas, true);
        }

        /// <summary>
        /// This method is used to start Synchronization Animation
        /// </summary>
        public void StartSyncAnimation()
        {
            imgSync.Visibility = Visibility.Visible;
            tbSync.Visibility = Visibility.Visible;
            Storyboard storyboardRotation = (Storyboard)FindResource("StoryboardRotation");
            storyboardRotation.Begin(rootCanvas, true);
        }

        /// <summary>
        /// This method is used to end Synchronization Animation
        /// </summary>
        public void EndSyncAnimation()
        {
            Storyboard storyboardRotation = (Storyboard)FindResource("StoryboardRotation");
            storyboardRotation.Stop(rootCanvas);
            Storyboard StoryboardEndSyncAnimation = (Storyboard)FindResource("StoryboardEndSyncAnimation");
            StoryboardEndSyncAnimation.Begin(rootCanvas);
        }

        #endregion
    }
}

